Add Xml.Escape helper method - #85
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## prime #85 +/- ##
==========================================
+ Coverage 85.31% 85.45% +0.14%
==========================================
Files 70 71 +1
Lines 1137 1176 +39
Branches 202 218 +16
==========================================
+ Hits 970 1005 +35
Misses 121 121
- Partials 46 50 +4 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Adds a small XML escaping utility to the PowerKit library (Xml.Escape(string)) to produce XML-safe text content by entity-escaping the five XML special characters and removing XML 1.0–illegal characters, with a no-allocation “no changes needed” fast path. Includes a focused test suite validating special-character escaping, invalid character removal, and surrogate handling.
Changes:
- Add
PowerKit.Xml.Escape(string)to escape& < > " 'and remove XML 1.0–illegal characters (including isolated surrogates). - Preserve valid supplementary characters via well-formed surrogate pairs.
- Add unit tests covering special chars, whitespace, control char removal, surrogate pairs, isolated surrogates, empty, and null.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| PowerKit/Xml.cs | Introduces Xml.Escape(string) with XML 1.0 character validity filtering and entity escaping. |
| PowerKit.Tests/XmlTests.cs | Adds unit tests validating escaping/removal rules and surrogate behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Adds a static
Xml.Escape(string str)helper for producing valid XML text from arbitrary strings.Changes
PowerKit/Xml.cs— newXmlstatic class withEscape(string str):&,<,>,",')#x9/#xA/#xD, isolated surrogates, U+FFFE/U+FFFF)PowerKit.Tests/XmlTests.cs— tests covering each special character, control char removal, surrogate pair preservation, isolated surrogate removal, empty string, and null inputExample